﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Pos.Model;

namespace Pos.DAL
{
    public class UserDAL
    {
        public int Add(UserInfo info)
        {
            Database db = new Database();
            SqlParameter[] param =
            {
                db.MakeOutParam("@ListID",SqlDbType.Int,4),
                db.MakeInParam("@Username",SqlDbType.VarChar,50,info.UserName),
                db.MakeInParam("@Password",SqlDbType.VarChar,50,info.Password),
            };
            try
            {
                db.ExecNonQuery("Pos_User_Add", param);
                return DataHelper.GetInt(param[0].Value).Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.Close();
            }
        }

        public int checkPassword(UserInfo info)
        {
            Database db = new Database();
            SqlParameter[] param =
            {
                db.MakeOutParam("@Result",SqlDbType.Int,4),
                db.MakeInParam("@Username",SqlDbType.VarChar,50,info.UserName),
                db.MakeInParam("@Password",SqlDbType.VarChar,50,info.Password),
            };
            try
            {
                db.ExecNonQuery("POS_User_CheckPassword", param);
                return DataHelper.GetInt(param[0].Value).Value;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                db.Close();
            }
        }
    }
}
